layui.use(['laytpl'], function(){
	var laytpl = layui.laytpl;

// 信息价渲染
var nowCity =sessionStorage.getItem("nowCity");
if(nowCity == null || nowCity == "null"){
	$.getJSON("http://restapi.amap.com/v3/ip?key=6a0ef5788c9d08d8e06effc034904740", function(result){
		if(result && result.status) {
			sessionStorage.setItem("nowCity",JSON.stringify(result));
			$.ajax({
				type:"post",
				url:"/guidance_service/front/guidance/getGuidanceName.do",
				data:{
					areaCode :result.adcode
				},success :function (data){
					console.log(data)
					var data = data.data.guidance ;
					laytpl(guidanceMain.innerHTML).render(data, function(html){	
						$("#guidanceList").append(html);
					});
					
				},error:function (){
					layer.msg("信息价请求错误，请稍后重试",{icon:2,time:3000});
				}
			});
		}
	});
}else{
	nowCity =  jQuery.parseJSON(nowCity);
	$.ajax({
		type:"post",
		url:"/guidance_service/front/guidance/getGuidanceName.do",
		data:{
			areaCode :nowCity.adcode
		},success :function (data){

			var data = data.data.guidance ;
			laytpl(guidanceMain.innerHTML).render(data, function(html){	
				$("#guidanceList").append(html);
			});
			
		},error:function (){
			layer.msg("信息价请求错误，请稍后重试",{icon:2,time:3000});
		}
	});
}
/*
   *  法规库渲染
   *	法律法规	10004 
   *  部门规章	10005
   *  行业协会	10000
   *  地方造价	19001
   *  专业部委	10002
   *
   * */
legal(10004)
legal(10005)
legal(10000)
legal(19001)
legal(10002)

function legal(sortId){
	$.ajax({
		type:"post",
		url:"/guidance_service/front/policies/searchPolicies.do",
		data:{
			fieldId :sortId
		},success:function (data){
			var data = data.data.list;
//			console.log(data)
			var allName = ["法律法规","部门规章","行业协会","地方造价","专业部委"];
			var allImg = ["line0","lower1","lower2","lower3","lower4"];
			var html = "<img src='/ceca_two/img/line1.png' class='policyImg'/><h1 class='policyName'><a href='' class='policyname'>法律法规</a></h1><hr /><dl class='policyTL'>"
			
			for (i = 0 ; i < 4 ; i++) {
				html += "<dd><i title='"+data[i].titles+"'>"+data[i].titles+"</i><a href='/ceca_two/modules/policy/policyDetails.html?fieldId="+data[i].fieldId+"&policiesId="+data[i].policiesId+"' class='look'>查看</a></dd>"				
			}
			html+="</dl>"
			
			switch (sortId){
				case 10004:
					$("#policy li").eq(0).append(html);
					$("#policy li").eq(0).find("img").attr({"src":"/ceca_two/img/line0.png"});
					$("#policy li").eq(0).find(".policyname").html("法律法规").attr("href","/ceca_two/modules/policy/policyList.html?fieldId=10004");
					break;
				case 10005:
					$("#policy li").eq(1).append(html);
					$("#policy li").eq(1).find("img").attr({"src":"/ceca_two/img/lower1.png"});
					$("#policy li").eq(1).find(".policyname").html("部门规章").attr("href","/ceca_two/modules/policy/policyList.html?fieldId=10005");
					break;
				case 10000:
					$("#policy li").eq(2).append(html);
					$("#policy li").eq(2).find("img").attr({"src":"/ceca_two/img/lower2.png"});
					$("#policy li").eq(2).find(".policyname").html("行业协会").attr("href","/ceca_two/modules/policy/policyList.html?fieldId=10000");
					break;
				case 19001:
					$("#policy li").eq(3).append(html);
					$("#policy li").eq(3).find("img").attr({"src":"/ceca_two/img/lower3.png"});
					$("#policy li").eq(3).find(".policyname").html("地方造价").attr("href","/ceca_two/modules/policy/policyList.html?fieldId=19001");
					break;
				case 10002:
					$("#policy li").eq(4).append(html);
					$("#policy li").eq(4).find("img").attr({"src":"/ceca_two/img/lower4.png"});
					$("#policy li").eq(4).find(".policyname").html("专业部委").attr("href","/ceca_two/modules/policy/policyList.html?fieldId=10002");
					break;
				default:
					break;
			}
			
			
		},error:function (){
			layer.msg("法规库请求错误，请稍后重试",{icon:2,time:3000});
		}
	});
}


//软件推荐



	$.ajax({
		type:"post",
		url:"/guidance_service/front/soft/category/getCategory.do",
		success:function (result){
//			console.log(result.data)
			
			laytpl(softwareNav.innerHTML).render(result.data, function(html){	
				$("#softwareNavBox").append(html);
			});
			
			$("#softwareNavBox li").on("click",function (){
				var thisCategoryId = $(this).attr("data-categoryId");
				$(this).addClass('first').siblings().removeClass("first")
				getSoftwareList(thisCategoryId)
			})
			
			console.log(result)
			if (result.data && result.data.length > 0) {
				getSoftwareList(result.data[0].categoryId)
			}else{
				layer.msg("软件推荐请求错误，请稍后重试",{icon:2,time:3000});
			}
			
			
		},
		error:function (){
			layer.msg("软件推荐导航请求错误，请稍后重试",{icon:2,time:3000});
		}
	});
	
	function getSoftwareList (categoryId){
		$.ajax({
			type:"post",
			url:"/guidance_service/front/soft/search.do",
			data:{
				categoryId : categoryId
			},success:function(result){
//				console.log(result.data.list)
				$("#softwareMain").empty();
				
				laytpl(softwareList.innerHTML).render(result.data.list, function(html){	
					$("#softwareMain").append(html);
				});
				$("#softwareMain .examine").attr("href","/ceca_two/modules/software/software.html?categoryId="+categoryId)
			},error:function (){
				layer.msg("软件推荐列表请求错误，请稍后重试",{icon:2,time:3000});
			}
		});
	}

	
	
})

